package com.zx.wangyixinwen.activity;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;

import com.zx.wangyixinwen.R;
import com.zx.wangyixinwen.fragment.IFragment;
import com.zx.wangyixinwen.fragment.NewsFragment;
import com.zx.wangyixinwen.fragment.ReadFragment;
import com.zx.wangyixinwen.fragment.FoundFragment;
import com.zx.wangyixinwen.fragment.TopicFragment;

public class MainActivity extends AppCompatActivity {
    private TabHost tabHost;
    private FragmentManager fm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.iv_drawer_item);
        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();

        // news
        View viewNews = getLayoutInflater().inflate(R.layout.image_news, null);
        TabHost.TabSpec tab_news = tabHost.newTabSpec("tab_news");
        tab_news.setIndicator(viewNews);
        tab_news.setContent(R.id.news);
        tabHost.addTab(tab_news);

        // read
        View viewRead = getLayoutInflater().inflate(R.layout.image_read, null);
        TabHost.TabSpec tab_read = tabHost.newTabSpec("tab_read");
        tab_read.setIndicator(viewRead);
        tab_read.setContent(R.id.read);
        tabHost.addTab(tab_read);

        // see
        View viewSee = getLayoutInflater().inflate(R.layout.image_see, null);
        TabHost.TabSpec tab_see = tabHost.newTabSpec("tab_see");
        tab_see.setIndicator(viewSee);
        tab_see.setContent(R.id.see);
        tabHost.addTab(tab_see);

        // topic
        View viewTopic = getLayoutInflater().inflate(R.layout.image_topic, null);
        TabHost.TabSpec tab_topic = tabHost.newTabSpec("tab_topic");
        tab_topic.setIndicator(viewTopic);
        tab_topic.setContent(R.id.topic);
        tabHost.addTab(tab_topic);

        // i
        View viewI = getLayoutInflater().inflate(R.layout.image_i, null);
        TabHost.TabSpec tab_i = tabHost.newTabSpec("tab_i");
        tab_i.setIndicator(viewI);
        tab_i.setContent(R.id.i);
        tabHost.addTab(tab_i);


        // 初始化碎片管理器
        fm = getSupportFragmentManager();
        // 初始化碎片业务类
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.news, new NewsFragment());
        transaction.replace(R.id.read, new FoundFragment());
        transaction.replace(R.id.see, new ReadFragment());
        transaction.replace(R.id.topic, new TopicFragment());
        transaction.replace(R.id.i, new IFragment());
        transaction.commit();
    }


}
